(function(window) {
	var vm;
	var devSN = "";
	var userName = "";
	var endTime = new Date().getTime();
	var startTime = new Date(new Date().toLocaleDateString()).getTime();

	function monitorPagePulldownRefresh(isPulldownRefresh) {
		var self = this;
		isPulldownRefresh = isPulldownRefresh === undefined ? true : isPulldownRefresh;
		setTimeout(function() {
			isPulldownRefresh && self.endPullDownToRefresh();
		}, 2000);
		v3Health.getHealthReport(devSN, function(code, data) {
			if(code === 0) {
				vm.score = data.finalscore;
			} else {
				vm.score = 0;
			}
		});
		v3DevlogServer.getDanger(devSN, startTime, endTime, function(code, data){
			if(code === 0){
				Vue.set(vm.dangerDate, 0, data[0] + data[1]);
				Vue.set(vm.dangerDate, 1, data[2] + data[3]);
				Vue.set(vm.dangerDate, 2, data[4] + data[5]);
				Vue.set(vm.dangerDate, 3, data[6] + data[7]);
			}else{
				
			}
		})
		v3Apmonitor.getKpistanumTwo(devSN, function(code, data){
			if(code === 0){
				Vue.set(vm.apstation, 0, data.ap_statistic.online + data.ap_statistic.offline);
				Vue.set(vm.apstation, 1, data.ap_statistic.online);
			}else{
				
			}
		})
		v3StaMonitor.getClientListCont(devSN, function(code, data){
			if(code === 0){
				Vue.set(vm.apstation, 2, data[0].totalCount);
				Vue.set(vm.apstation, 3, data[0].conditionCount);
			}
		})
		v3DevMonitor.getCpuinfo(devSN, function(code, data){
			console.log(devSN);
			console.log(JSON.stringify(data));
			if(data.errCode === 0){
				Vue.set(vm.cpuinfo, 0, data.cpuInfo.cpuRatio);
				Vue.set(vm.cpuinfo, 1, data.cpuInfo.highestCpuRatio);
			}else{
				
			}
		})
		v3DevMonitor.getMemoryinfo(devSN, function(code, data){
			if(data.errCode === 0){
				Vue.set(vm.memorinfo, 0, data.memoryInfo.memoryRatio);
				Vue.set(vm.memorinfo, 1, data.memoryInfo.highestMemoryRatio);
			}else{
				
			}
		})
		v3DevMonitor.getDevspeed(devSN, function(code, data){
			if(data.errCode === 0){
				Vue.set(vm.devspeed, 0, data.speed.speed_up);
				Vue.set(vm.devspeed, 1, data.speed.speed_down);
			}else{
				
			}
		})
	}

	function mounted() {
		vm = this;
		mui.plusReady(function() {
			devSN = $.util.getDevSN();
			console.log(devSN);
			userName = dataManager.getUserName();
			monitorPagePulldownRefresh(false);
//			//阻尼系数
//          var deceleration = mui.os.ios?0.003:0.0009;
//          
//			$('.mui-scroll-wrapper').scroll({
//				indicators: true, //是否显示滚动条
//				bounce: false,
//				deceleration: deceleration
//			});

			$("#monitor-scroll").pullToRefresh({
				down: {
					callback: monitorPagePulldownRefresh
				}
			});
		});
	}

	window.monitor = {
		mounted: mounted,
		data: {
			score: 0,
			dangerDate: [0,0,0,0],
			apstation: [0,0,0,0],
			cpuinfo: [0,0],
			memorinfo: [0,0],
			devspeed: [0,0]
		},
		methods: {
			//monitorPagePulldownRefresh:monitorPagePulldownRefresh
		},
		computed: {
			echartsOption: function() {
				return {
					series: [{
						type: 'gauge',
						min: 0,
						max: 100,
						splitNumber: 6,
						splitLine: {
							length: 18
						},
						axisTick: {
							show: false
						},
						axisLabel: {
							show: false
						},
						axisLine: { // 坐标轴线
							show: true, // 默认显示，属性show控制显示与否
							lineStyle: { // 属性lineStyle控制线条样式
								color: [
									[0.166, '#ff7e78'],
									[0.332, '#FFC833'],
									[0.498, '#C3E6E8'],
									[0.664, '#A6DCDC'],
									[0.83, '#69C4C5'],
									[1, '#69C4C5']
								],
								width: 18
							}
						},
						detail: {
							formatter: '{value} 分',
							offsetCenter: [0, '65%'],
							textStyle: {
								color: '#666',
								fontSize: 28
							}
						},
						data: [{
							value: this.score
						}]
					}, {
						type: 'pie',
						animation: false,
						radius: ['79%', '80%'],
						labelLine: {
							normal: {
								show: false
							}
						},
						itemStyle: {
							normal: {
								color: '#eee'
							}
						},
						data: [{
							value: 0
						}]
					}]
				};
			}
		},
	};
})(window);
